package com.loong.framework.response;

import lombok.Data;

/**
 * @author : ten.x
 * @date : 2022-03-16
 */
@Data
public class CommonResult<T> {

  private Integer code;

  private String msg;

  private T data;

  public CommonResult(T date) {
    this.code = CommonEnum.OK.getCode();
    this.msg = CommonEnum.OK.getMsg();
    this.data = date;
  }

  public CommonResult(Integer status, String msg, T data) {
    this.code = status;
    this.msg = msg;
    this.data = data;
  }

  public static <T> CommonResult<T> success() {
    return new CommonResult<>(null);
  }

  public static <T> CommonResult<T> success(T data) {
    return new CommonResult<>(data);
  }

  public static <T> CommonResult<T> success(T data, String msg) {
    return new CommonResult<>(CommonEnum.OK.getCode(), msg, data);
  }

  public static <T> CommonResult<T> fail(String msg) {
    return new CommonResult<>(CommonEnum.FAIL_EXCEPTION.getCode(), msg, null);
  }

  public static <T> CommonResult<T> fail(String msg, T data) {
    return new CommonResult<>(CommonEnum.FAIL_EXCEPTION.getCode(), msg, data);
  }

  public static <T> CommonResult<T> fail(Integer code, String msg, T data) {
    return new CommonResult<>(code, msg, data);
  }

  public static <T> CommonResult<T> fail(Integer code, String msg) {
    return new CommonResult<>(code, msg, null);
  }
}
